//
//  ViewController.m
//  UI26_Masonry
//
//  Created by dllo on 16/8/18.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 1. 使用Masonry不用给初始frame 一定要将约束的视图先添加到父视图
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:view];
    // 设置该视图约束
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.top.bottom.mas_equalTo(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(100);
        make.bottom.mas_equalTo(-100);
    }];
    
    UIView *secView = [UIView new];
    secView.backgroundColor = [UIColor redColor];
    [view addSubview:secView];
    [secView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(view.mas_width).multipliedBy(0.8);
    }];
    // 添加黄色视图 与红色 等高 等宽 相聚10
    UIView *yellowView = [UIView new];
    yellowView.backgroundColor = [UIColor yellowColor];
    [view addSubview:yellowView];
    [yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.centerX.mas_equalTo(secView);
        make.top.mas_equalTo(secView.mas_bottom).mas_offset(10);
    }];
    
    UILabel *label = [UILabel new];
    label.text = @"sd;fksldkfkksddfll;ekf;lsdf;lsdfkls;dfs;dlfs;dfkslfkslfkldkfkgkdgldksflksdfl";
    label.backgroundColor = [UIColor brownColor];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.centerX.height.mas_equalTo(secView);
        make.bottom.mas_equalTo(secView.mas_top).mas_offset(-10);
    }];
    
    [NSLayoutConstraint constraintWithItem:yellowView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
